package com.copy;

import java.io.*;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-28
 */
public class FileCopy {
    public static void main(String[] args) {
        String fileFather = "D:\\CScode\\code\\java_code\\2024\\t0728\\src\\com";
        String fileSon = "picture.jpg";
        String fileSonDest = "myIcon.jpg";
        File fileName = new File(fileFather, fileSon);
        File fileDest = new File(fileFather, fileSonDest);
        FileInputStream fileIn = null;
        FileOutputStream fileOut = null;

        try {
            fileIn = new FileInputStream(fileName);
            fileOut = new FileOutputStream(fileDest);
            int readLen = 0;
            byte[] buf = new byte[1024];


            //输入到内存中
            while ((readLen = fileIn.read(buf)) != -1) {
                //输出到文件中
                fileOut.write(buf, 0, readLen);
            }
            System.out.println("拷贝成功！");

        } catch (IOException e) {
            System.out.println("创建输入输出流失败");;
        } finally {
            try {
                if (fileIn != null) {
                    fileIn.close();
                }
                if (fileOut != null) {
                    fileOut.close();
                }
            } catch (IOException e) {
                System.out.println("关闭流失败");
            }
        }
    }
}
